import router from './index.js';
import { getToken, removeToken, removeUserName } from '@/utils/app.js';
import store from '@/store/index';

const whiteRouter = ['/login']
router.beforeEach((to, from, next) => {
    if (getToken()) {
        // console.log(to)
        if (to.path === '/login') {
            removeToken()
            removeUserName()
            store.commit('app/SET_TOKEN', '')
            store.commit('app/SET_USERNAME', '')
            next()
        } else {
            //获取用户角色
            //分配路由权限
            next()
        }
    } else {
        if (whiteRouter.indexOf(to.path) !== -1) {
            next();
        } else {
            next('/login')
        }
    }
    // next()
})